#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File Name: 各种栈实现的性能比较_stacktimetest.py
@Author: LT
@Date: 2021/9/27 14:00
# -----------------------------------------------------------------------------------------------------
@Description: 
python .\各种栈实现的性能比较_stacktimetest.py 200 200 0
# -----------------------------------------------------------------------------------------------------
"""
import 一个堆栈类_stack2 as stack2                               # 单纯基于列表的栈: [x]+y
import 优化_基于元组树的栈_stack3 as stack3                          # 基于元组树的栈: (x,y)
import 优化_基于列表可原地修改的特性实现更快速_stack4 as stack4        # 原地修改列表的栈:   y.append(x)
import 简单的测时工具_timer as timer                               # 即使模块
from sys import argv

rept = 200
pushes, pops, items = (int(arg) for arg in argv[1:])            # sys.argv分别为压栈数、出栈数、取索引数


def stackops(stackClass):
    x = stackClass('spam')                                      # 创建栈对象
    for i in range(pushes):                                     # 压栈那么多次
        x.push(i)
    for i in range(items):                                      # 取索引那么多次
        t = x[i]
    for i in range(pops):                                       # 出栈那么多次
        x.pop()

    # or mod = __import__(n)


for mod in (stack2, stack3, stack4):  # rept*(push+pop+ix)
    print('%s:' % mod.__name__, end=' ')
    print(timer.test(rept, stackops, getattr(mod, 'Stack')))

if __name__ == '__main__':
    pass
